package com.fancy.learncenter.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.fancy.learncenter.common.MyApplication;

public class SPUtils {
    private final static String PREFERENCE_NAME = "fancy_flc";

    private static String isFirst_key = "isFirst";

    private static String isSearchRecord_key = "isSearchRecord";

    /**
     * 是否第一次安装
     *
     * @param value true 更新数据
     * @return
     */
    public static boolean first(boolean value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(isFirst_key, value);
        return editor.commit();
    }

    public static boolean isFirst() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);

        if (settings.getBoolean(isFirst_key, true)) {
            return true;
        } else {
            return false;
        }
    }


    /**
     * 搜索记录
     *
     * @param value
     * @return
     */
    public static boolean putSearchRecord(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(isSearchRecord_key, value);
        return editor.commit();
    }

    /**
     * 获取搜索记录
     *
     * @return
     */
    public static String getSearchRecord() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString(isSearchRecord_key, "");
    }

    /**
     * 设置默认班级ID
     *
     * @param value
     * @return
     */
    public static boolean putClassID(String value) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("classId", value);
        return editor.commit();
    }

    /**
     * 获取默认班级ID
     * 字符串形式  classID+","+className
     *
     * @return
     */
    public static String getClassID() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getString("classId", "");
    }

    /**
     * 设置老师角色
     *
     * @param value
     * @return
     */
    public static boolean putTeacherRole(boolean value) {
        LogUtil.MyLog("putTeacherRole",  "======putTeacherRole=======" + SPUtils.gettTeacherRole());
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("TeacherRole", value);
        return editor.commit();
    }

    /**
     * 获取默认班级ID
     * 字符串形式  classID+","+className
     *
     * @return
     */
    public static boolean gettTeacherRole() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getBoolean("TeacherRole", false);
    }

    /**
     * 设置学生角色
     *
     * @param value
     * @return
     */
    public static boolean putStudentRole(boolean value) {
        LogUtil.MyLog("putTeacherRole",  "======putStudentRole=======" + SPUtils.gettTeacherRole());
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("mStudentRole", value);
        return editor.commit();
    }

    /**
     * 获取默认班级ID
     * 字符串形式  classID+","+className
     *
     * @return
     */
    public static boolean gettStudentRole() {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        return settings.getBoolean("mStudentRole", false);
    }

    /**
     * @return
     */
    public static boolean putJSESSIONID(String jsid) {
        SharedPreferences settings = MyApplication.context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("JSESSIONID", jsid);
        return editor.commit();
    }


}